package cn.xny.basic.service.impl;

import cn.xny.basic.mapper.BaseMapper;
import cn.xny.basic.query.BaseQuery;
import cn.xny.basic.service.BaseService;
import cn.xny.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)

public class BaseServiceImpl<T> implements BaseService<T> {

  @Autowired
  private BaseMapper<T> baseMapper;

    // 添加
    @Transactional
    @Override
    public void save(T t) {
               baseMapper.save(t);
    }
    // 修改
    @Transactional
    @Override
    public void update(T t) {
             baseMapper.update(t);
    }
    // 删除
    @Transactional
    @Override
    public void del(Long id) {
         baseMapper.del(id);
    }

    // 查询单条
    @Override
    public T loadByAll(Long id) {

        return baseMapper.loadByAll(id);
    }
    // 查询所有
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    //做分页+高级查询
    @Override
    public PageList<T> pageQuery(BaseQuery query) {
        Integer totatls = baseMapper.queryCount(query);
          if(totatls==null){
              return new PageList<>();
          }
        List<T> data = baseMapper.queryData(query);

          return new PageList<>(data,totatls);
    }


    @Transactional
    @Override
    public void patchDelete(List<Long> ids) {
          baseMapper.patchDelete(ids);
    }


}
